using UnityEngine;
using UnityEngine.Experimental.Rendering;

namespace Mars.ShaderAnalysis
{
    public static class GraphicsUtility
    {
        public static int GetGraphicsFormatBits(GraphicsFormat format)
        {
            int bits = 0;
            switch (format)
            {
                case GraphicsFormat.R8_SRGB:
                case GraphicsFormat.R8_UNorm:
                case GraphicsFormat.R8_SNorm:
                case GraphicsFormat.R8_UInt:
                case GraphicsFormat.R8_SInt:
                case GraphicsFormat.S8_UInt:
                {
                    bits = 8;
                    break;
                }
                case GraphicsFormat.R8G8_SRGB:
                case GraphicsFormat.R8G8_UNorm:
                case GraphicsFormat.R8G8_SNorm:
                case GraphicsFormat.R8G8_UInt:
                case GraphicsFormat.R8G8_SInt:
                case GraphicsFormat.R16_UNorm:
                case GraphicsFormat.R16_SNorm:
                case GraphicsFormat.R16_UInt:
                case GraphicsFormat.R16_SInt:
                case GraphicsFormat.R16_SFloat:
                case GraphicsFormat.R4G4B4A4_UNormPack16:
                case GraphicsFormat.B4G4R4A4_UNormPack16:
                case GraphicsFormat.R5G6B5_UNormPack16:
                case GraphicsFormat.B5G6R5_UNormPack16:
                case GraphicsFormat.R5G5B5A1_UNormPack16:
                case GraphicsFormat.B5G5R5A1_UNormPack16:
                case GraphicsFormat.A1R5G5B5_UNormPack16:
                case GraphicsFormat.D16_UNorm:
                {
                    bits = 16;
                    break;
                }
                case GraphicsFormat.R8G8B8_SRGB:
                case GraphicsFormat.R8G8B8_UNorm:
                case GraphicsFormat.R8G8B8_SNorm:
                case GraphicsFormat.R8G8B8_UInt:
                case GraphicsFormat.R8G8B8_SInt:
                case GraphicsFormat.B8G8R8_SRGB:
                case GraphicsFormat.B8G8R8_UNorm:
                case GraphicsFormat.B8G8R8_SNorm:
                case GraphicsFormat.B8G8R8_UInt:
                case GraphicsFormat.B8G8R8_SInt:
                {
                    bits = 24;
                    break;
                }
                case GraphicsFormat.R8G8B8A8_SRGB:
                case GraphicsFormat.R8G8B8A8_UNorm:
                case GraphicsFormat.R8G8B8A8_SNorm:
                case GraphicsFormat.R8G8B8A8_UInt:
                case GraphicsFormat.R8G8B8A8_SInt:
                case GraphicsFormat.R16G16_UNorm:
                case GraphicsFormat.R16G16_SNorm:
                case GraphicsFormat.R16G16_UInt:
                case GraphicsFormat.R16G16_SInt:
                case GraphicsFormat.R16G16_SFloat:
                case GraphicsFormat.R32_UInt:
                case GraphicsFormat.R32_SInt:
                case GraphicsFormat.R32_SFloat:
                case GraphicsFormat.B8G8R8A8_SRGB:
                case GraphicsFormat.B8G8R8A8_UNorm:
                case GraphicsFormat.B8G8R8A8_SNorm:
                case GraphicsFormat.B8G8R8A8_UInt:
                case GraphicsFormat.B8G8R8A8_SInt:
                case GraphicsFormat.E5B9G9R9_UFloatPack32:
                case GraphicsFormat.B10G11R11_UFloatPack32:
                case GraphicsFormat.A2B10G10R10_UNormPack32:
                case GraphicsFormat.A2B10G10R10_UIntPack32:
                case GraphicsFormat.A2B10G10R10_SIntPack32:
                case GraphicsFormat.A2R10G10B10_UNormPack32:
                case GraphicsFormat.A2R10G10B10_UIntPack32:
                case GraphicsFormat.A2R10G10B10_SIntPack32:
                case GraphicsFormat.A2R10G10B10_XRSRGBPack32:
                case GraphicsFormat.A2R10G10B10_XRUNormPack32:
                case GraphicsFormat.R10G10B10_XRSRGBPack32:
                case GraphicsFormat.R10G10B10_XRUNormPack32:
                case GraphicsFormat.A10R10G10B10_XRSRGBPack32:
                case GraphicsFormat.A10R10G10B10_XRUNormPack32:
                case GraphicsFormat.D24_UNorm:
                case GraphicsFormat.D24_UNorm_S8_UInt:
                case GraphicsFormat.D32_SFloat:
                case GraphicsFormat.D32_SFloat_S8_UInt:
                {
                    bits = 32;
                    break;
                }
                case GraphicsFormat.R16G16B16_UNorm:
                case GraphicsFormat.R16G16B16_SNorm:
                case GraphicsFormat.R16G16B16_UInt:
                case GraphicsFormat.R16G16B16_SInt:
                {
                    bits = 48;
                    break;
                }
                case GraphicsFormat.R16G16B16A16_UNorm:
                case GraphicsFormat.R16G16B16A16_SNorm:
                case GraphicsFormat.R16G16B16A16_UInt:
                case GraphicsFormat.R16G16B16A16_SInt:
                case GraphicsFormat.R16G16B16A16_SFloat:
                case GraphicsFormat.R32G32_UInt:
                case GraphicsFormat.R32G32_SInt:
                case GraphicsFormat.R32G32_SFloat:
                {
                    bits = 64;
                    break;
                }
                case GraphicsFormat.R32G32B32_UInt:
                case GraphicsFormat.R32G32B32_SInt:
                case GraphicsFormat.R32G32B32_SFloat:
                {
                    bits = 96;
                    break;
                }
                case GraphicsFormat.R32G32B32A32_UInt:
                case GraphicsFormat.R32G32B32A32_SInt:
                case GraphicsFormat.R32G32B32A32_SFloat:
                {
                    bits = 128;
                    break;
                }
                case GraphicsFormat.None:
                {
                    bits = 0;
                    break;
                }
                default:
                {
                    Debug.LogError("未知GraphicsFormat : " + format);
                    bits = -1;
                    break;
                }
            }

            return bits;
        }
    }
}